using System.Windows.Input;
using Bookvar.ObjectModel;
using Bookvar.UI.Commands;

namespace Bookvar.UI.ViewModel
{
    internal partial class MindmapViewModel
    {
        private class DeleteResourceCommand : CommandModel
        {
            private readonly MindmapViewModel viewModel;

            public DeleteResourceCommand(MindmapViewModel viewModel)
                : base( BookvarCommands.DeleteResource )
            {
                this.viewModel = viewModel;
            }

            protected internal override void OnExecute( object sender, ExecutedRoutedEventArgs e )
            {
                Resource resource = e.Parameter as Resource;
                if (resource != null)
                {
                    var action = TopicActions.CreateDeleteResourceAction(
                        resource, viewModel.SelectedTopic, viewModel.Mindmap );
                    ActionService.Execute( action );
                }
            }

            protected internal override void OnCanExecute( object sender, CanExecuteRoutedEventArgs e )
            {
                e.CanExecute = e.Parameter is Resource;
                e.Handled = true;
            }
        }
    }
}